const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const User = require('./User');
const Job = require('./job');

const Company = sequelize.define('Company', {
  id: {
    type: DataTypes.UUID,
    primaryKey: true,
    defaultValue: DataTypes.UUIDV4
  },
  name: {
    type: DataTypes.STRING,
    allowNull: false,
    validate: {
      notEmpty: true
    }
  },
  description: {
    type: DataTypes.TEXT
  },
  industry: {
    type: DataTypes.STRING
  },
  scale: {
    type: DataTypes.STRING,
    validate: {
      isIn: [['少于50人', '50-100人', '100-500人', '500-1000人', '1000人以上']]
    }
  },
  address: {
    type: DataTypes.STRING
  },
  contactPerson: {
    type: DataTypes.STRING
  },
  contactPhone: {
    type: DataTypes.STRING
  },
  contactEmail: {
    type: DataTypes.STRING,
    validate: {
      isEmail: true
    }
  },
  website: {
    type: DataTypes.STRING
  },
  logo: {
    type: DataTypes.STRING
  },
  status: {
    type: DataTypes.STRING,
    defaultValue: 'pending',
    validate: {
      isIn: [['pending', 'approved', 'rejected']]
    }
  }
});

// 关联关系
Company.hasMany(Job);
Job.belongsTo(Company);

User.hasOne(Company);
Company.belongsTo(User);

module.exports = Company;